package com.tarena.lbs.coupon.enums;

import lombok.Getter;

/**
 * @author: Feng-hongliang
 * @date: 2025/10/13 9:12
 * @Version: 1.0
 * @description: 优惠券类型枚举
 */
@Getter
public enum CouponTypeEnum {
    /**
     * 现金券
     */
    CASH(0, "现金券"),

    /**
     * 满减券
     */
    FULL_REDUCTION(1, "满减券"),

    /**
     * 满折券
     */
    FULL_DISCOUNT(2, "满折券"),

    /**
     * 随机券
     */
    RANDOM(3, "随机券"),

    /**
     * 折扣券
     */
    DISCOUNT(4, "折扣券");


    private final Integer code;
    private final String description;

    CouponTypeEnum(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据code获取优惠券类型枚举
     *
     * @param code 类型编码
     * @return 优惠券类型枚举
     */
    public static CouponTypeEnum fromCode(Integer code) {
        for (CouponTypeEnum type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown coupon type code: " + code);
    }
}